﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.DataAccess.Common;
using T.FAS.Runtime.DataAccess.SPI;

namespace T.FAS.Runtime.DataAccess.Engine
{
    /// <summary>
    /// 数据访问接口适配器工厂
    /// </summary>
    class DatabaseFactory
    {
        public static IDatabase CreateDefaultDatabase()
        {
            return new DatabaseImpl();
        }

        public static IDatabase CreateDatabase(CompositeDataObject CompositeDataObject)
        {
            var mainDbType = EnumTools.Convert<DbType>(CompositeDataObject.RootCompositeNodeObject.DataObject.Database.DbType);

            return CreateDatabase(mainDbType);
        }

        public static IDatabase CreateDatabase(DbType mainDbType)
        {
            switch (mainDbType)
            {
                case DbType.ES:
                    return new ESDatabase();
                case DbType.SQLServer:
                case DbType.MySQL:
                case DbType.Oracle:
                    return CreateDefaultDatabase();
                default:
                    return CreateDefaultDatabase();
            }
        }


    }
}
